/**
 * Copyright (c) 2018, Alex. All rights reserved.
 */
package com.oschina.bottle.common.constants;

import com.oschina.bottle.common.exception.BaseException;
import java.io.UnsupportedEncodingException;

/**
 * 编码常量
 *
 * @author <a href="mailto:zhongchao@gegejia.com">zhong</a>
 * @version 1.0 2018/1/5
 * @since 1.0
 */
public class Charset {

    public final static String UTF8 = "UTF-8";

    public final static String GBK = "GBK";

    public final static String GB2312 = "GB2312";

    public static byte[] formatUTF8(String data) {
        if(null == data) {
            throw new IllegalArgumentException("the data must not be null");
        }

        try {
            return data.getBytes(UTF8);
        } catch (UnsupportedEncodingException e) {
            throw new BaseException("unsupported encode %s", UTF8);
        }
    }
}
